package com.an.blog.strategy.context;

import com.an.blog.strategy.SearchStrategy;
import com.an.blog.web.domain.bo.BlogArticleWebBo;
import com.an.blog.web.domain.vo.BlogArticleDetailWebVo;
import com.an.blog.web.domain.vo.BlogArticleWebVo;
import com.an.common.core.domain.PageQuery;
import com.an.common.core.page.TableDataInfo;
import com.an.common.enums.BlogSearchType;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 搜索策略上下文
 *
 * @author Ann
 * @date 2024/07/08
 */
@Service
@AllArgsConstructor
public class SearchStrategyContext {

    private Map<String, SearchStrategy> searchStrategyContextMap;


    /**
     * 查询网页列表
     *
     * @param esEnabled    ES 已启用
     * @param articleWebBo 文章 web bo
     * @param pageQuery    页面查询
     * @author Ann
     * @date 2024/07/25
     */
    public TableDataInfo<BlogArticleWebVo> executeQueryWebPageList(Boolean esEnabled, BlogArticleWebBo articleWebBo, PageQuery pageQuery) {
        return searchStrategyContextMap.get(BlogSearchType.getStrategyByEsEnabledConfig(esEnabled))
            .queryWebPageList(articleWebBo, pageQuery);
    }

    /**
     * 按 ID 执行查询 Web 详细信息
     *
     * @param esEnabled ES 已启用
     * @param articleId 文章ID
     * @return {@link BlogArticleDetailWebVo }
     * @author Ann
     * @date 2024/08/05
     */
    public BlogArticleDetailWebVo executeQueryWebDetailById(Boolean esEnabled, Long articleId) {
        return searchStrategyContextMap.get(BlogSearchType.getStrategyByEsEnabledConfig(esEnabled))
            .queryWebDetailById(articleId);
    }
}
